package com.bw.permission.config;

import com.bw.permission.common.AjaxResult;
import com.bw.permission.common.BizException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常拦截
 * @author zhanggm
 * @date 2021/8/18 16:51
 */

@RestControllerAdvice
public class GlobalExeceptHandler {

    @ExceptionHandler(Exception.class)
    public AjaxResult handlerException(Exception e) {
        e.printStackTrace();
        return AjaxResult.err(500, e.getMessage());
    }

    @ExceptionHandler(BizException.class)
    public AjaxResult handlerException(BizException biz) {
        biz.printStackTrace();
        return AjaxResult.err(biz.getErrCode(), biz.getMessage());
    }
}
